/*
 * log.h
 *
 *  Created on: 22/10/2011
 *      Author: utn_so
 */

#ifndef OLD_LOG_H_
#define OLD_LOG_H_

        #define _XOPEN_SOURCE 500

        #include <stdio.h>
        #include <pthread.h>
        #include <stdarg.h>

        #define LOG_MAX_MESSAGE_LENGTH 2048

        typedef enum {
                M_CONSOLE_DISABLE       = 1,
                M_CONSOLE_ENABLE        = 2
        } e_console_mode;

        typedef enum {
                ERROR           = 1,
                WARNING         = 2,
                INFO            = 4,
                DEBUG           = 8
        } e_message_level;

        typedef struct {
                FILE* file;
                char *program_name;
                int program_pid;
                unsigned char log_levels;
                e_console_mode console_mode;
                pthread_mutex_t mutex;
        } t_log;

        t_log*  log_create(const char *program_name, const char* file_name, unsigned char log_levels, e_console_mode console_mode);
        int     log_info(t_log* log, const char *thread_name, const char *format, ... );
        int     log_warning(t_log* log, const char *thread_name, const char *format, ... );
        int     log_error(t_log* log, const char *thread_name, const char *format, ... );
        int     log_debug(t_log* log, const char *thread_name, const char *format, ... );
        #define log_has_level(log, level)       ((log->log_levels & level) == level)
        void    log_destroy(t_log *log);

#endif /*OLD_LOG_H_*/
